'use strict'
const CompressionWebpackPlugin = require('compression-webpack-plugin')
const webpack = require('webpack')
const path = require('path')
function resolve(dir) {
    return path.join(__dirname, dir)
}
var urlProxy = process.env.VUE_APP_LAYER_API

// All configuration item explanations can be find in https://cli.vuejs.org/config/
module.exports = {
    // hash 模式下可使用
    // publicPath: process.env.NODE_ENV === 'development' ? '/' : './',
    publicPath: '/',
    outputDir: 'dist',
    assetsDir: 'static',
    lintOnSave: false, // true
    productionSourceMap: false,
    // parallel: false,
    devServer: {
        open: true,
        overlay: {
            warnings: false,
            errors: true
        },
        proxy: {
            '/mapData': {
                target: urlProxy + ':8190/mapData',
                // target: urlProxy + ':8080/mapData',
                ws: true,
                changeOrigin: true,
                pathRewrite: {	// 重写路径
                    '^/mapData': ''
                }
            },
            '/FileDirectory': {
                target: urlProxy + ':6054/FileDirectory',
                // target: urlProxy + ':8060/FileDirectory',
                ws: true,
                changeOrigin: true,
                pathRewrite: {	// 重写路径
                    '^/FileDirectory': ''
                }
            },

            '/nodeserve': {
                target: urlProxy + ':8080/nodeserve',
                ws: true,
                changeOrigin: true,
                pathRewrite: {	// 重写路径
                    '^/nodeserve': ''
                }
            },

            '/Upload': {
                target: 'http://183.6.105.178:8015/Upload',
                ws: true,
                changeOrigin: true,
                pathRewrite: {	// 重写路径
                    '^/Upload': ''
                }
            },
            '/sendMessage': {
                target: 'http://10.61.10.151:5002/api',
                changeOrigin: true,
                pathRewrite: {	// 重写路径
                    '^/sendMessage': ''
                }
            }
        }
    },
    // 配置css前缀,px转rem
    css: {
        loaderOptions: {
            postcss: {
                // exclude: ['/src/views', '/src/components', path.join(__dirname, '..', '/src/views')],
                plugins: [
                    require('postcss-plugin-px2rem')({
                        rootValue: 16, // 换算基数， 默认100  ，可以设置为75这样的话把根标签的字体规定为1rem为50px,这样就可以从设计稿上量出多少个px直接在代码中写多上px了。
                        mediaQuery: false, // （布尔值）允许在媒体查询中转换px。
                        minPixelValue: 3 // 设置要替换的最小像素值(3px会被转rem)。 默认 0
                    })
                ]
            }
        }
    },
    configureWebpack: {
        resolve: {
            alias: {
                '@': resolve('src')
            }
        },
        plugins: [
            new CompressionWebpackPlugin({
                algorithm: 'gzip',
                test: new RegExp('\\.(' + ['js', 'css'].join('|') + ')$'),
                threshold: 1024,
                minRatio: 0.8
            }),
            new webpack.optimize.LimitChunkCountPlugin({
                maxChunks: 10,
                minChunkSize: 100
            })
        ],
        module: {
            unknownContextCritical: false
        },
        externals: {
            'MathLive': 'MathLive'
        }
    },
    chainWebpack(config) {
        // config.when(true, config => config.devtool('source-map'))
        // config.plugin('webpack-bundle-analyzer').use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
        // if (process.env.NODE_ENV === 'production') {
        //     config.plugin('compressionPlugin').use(
        //         new CompressionWebpackPlugin({
        //             // test: /\.(js|css|less)$/, // 匹配文件名
        //             test: /\.(js)$/, // 匹配文件名
        //             threshold: 2048, // 对超过10k的数据压缩
        //             minRatio: 0.8,
        //             deleteOriginalAssets: true // 删除源文件
        //         })
        //     )
        // }
    },
    transpileDependencies: [
        'vue-echarts',
        'resize-detector'
    ]
}
